package com.ymttest.database.mongo;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.UUID;

import com.ymt.core.tool.FormatUtil;
import com.ymt.core.tool.Logger;
import com.ymt.database.MongoDBDriver;
import com.ymttest.utils.EnvSetup;

public class MessageWapper {
	MongoDBDriver mdd;

	public MessageWapper() throws Exception {
		
		}

	/**
	 * 用uid查询AccessToken
	 * 
	 * @param uid
	 * @return AccessToken
	 * @throws Exception
	 */
	public MessageBean getMessageByMid(String appName,String codeName,String mid) throws Exception {
		
		SimpleDateFormat   sDateFormat   =   new   SimpleDateFormat("yyyyMM");   
		String   date   =   sDateFormat.format(new   java.util.Date());  
		
		mdd = new MongoDBDriver(EnvSetup.getSystemUrl("set5_mongoip"), Integer.valueOf(EnvSetup
				.getSystemUrl("set5_mongoport")), "MQ_Message_"+appName+"_"+date);
		mdd.selectCollection("Message_"+appName+"_"+codeName);
	
		String re = null;
		MessageBean mb = null;
		//ArrayList<String> list = mdd.selectPartLimit("{\"mid\":" + mid + "}", 1);
		ArrayList<String> list = mdd.selectPartLimit("{\"mid\":\"" + mid + "\"}", 1);
		try {
			if (list.size() > 0) {
				re = list.get(0);
				mb = (MessageBean) FormatUtil.GSONToObject(re, MessageBean.class);
				return mb;
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}

	public static void main(String args[])
	{
		try {
			MessageBean MessageBean =new MessageWapper().getMessageByMid("bamei","qusi","123");
			Logger.comment(MessageBean.getBody());
			Logger.comment(MessageBean.getCtime().toString());
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}
